<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // 拷贝继承：  在构造函数的内部实例化父类(传参)，通过深拷贝的形式把父类的实例上的所有属性和方法拷贝到子类的prototype上


        function Dog(name, age) {
            this.name = name;
            this.age = age;
            this.type = '狗';
        }

        Dog.prototype.say = function () {
            console.log('汪');
        }



        function KeJi(name, age, color) {

            this.color = color ;

            const d = new Dog(name , age) ;

            // for in 遍历对象
            //    把属性和方法都拷贝到了子类的prototype上面的
            for(let k in d) {
                KeJi.prototype[k] = d[k]
            } 
            
        }


        KeJi.prototype.speak = function(){
            console.log('hi');
        }


        const k = new KeJi('旺财' , 2 , '白色') ;
        console.log(k);
 




        const obj = {
            a:1 ,
            b:2
        }


        // const obj2 = obj ;

        // const obj2 = {} ;

        // for(let k in obj) {
        //     obj2[k] = obj[k]
        // }

        // console.log(obj2);






    </script>

</body>

</html>